#include <iostream>
using namespace std;

const int N = 1e5 + 10;

long long t, n, k, ret;
char s[N];


int main()
{
    cin >> t;
    while (t--)
    {
        cin >> n >> k >> s;

        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'L') ret--;
            else
            {
                if (i - 1 >= 0 && i - 2 >= 0 && s[i - 1] == 'W' && s[i - 2] == 'W')
                    ret += k;
                else
                    ret++;
            }
        }

        cout << ret << endl;
        ret = 0;
    }

    return 0;
}